<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/28
 * Time: 19:17
 */

namespace app\admin\model;


class CourseClass extends Base
{
    public function cateTree()
    {
        $model = self::all();
        return $this->sort($model);
    }

    public function sort($data,$pid=0,$level=0)
    {
        static $arr = array();
        foreach ($data as $k=>$v){
            if ($v['pid'] == $pid){
                $v['level'] = $level;
                $arr[] = $v;
                $this->sort($data,$v['id'],$level+1);
            }
        }
        return $arr;
    }

    public function getchilrenid($cateid)
    {
        $res=$this->select();
        return $this->_getchilrenid($res,$cateid);
    }

    public function _getchilrenid($res,$cateid){
        static $arr=array();
        foreach($res as $k=>$v){
            if($v['pid'] == $cateid){
                $arr[]=$v['id'];
                $this->_getchilrenid($res,$v['id']);
            }
        }
        return $arr;
    }
}